import config from "../../utils/config";
import {request} from "../../utils/request";
Page({
    data: {
        custom: wx.getMenuButtonBoundingClientRect(),
        user:{},
        user_id:'',
        username:'',
        password:'',
        re_password:''
    },
    onLoad: function (options) {
        var user = wx.getStorageSync('userInfo')
        this.setData({
            user,
            user_id:user.id,
            username:user.username,
        })
    },
    changeValue(e) {
        var field = e.currentTarget.dataset.field,
            value = e.detail.value
        this.setData({[field]: value})
    },
    submit(){
        if(!this.data.username){
            config.toast('登录账号不能为空',201,()=>{})
            return false;
        }
        if(!this.data.password){
            config.toast('登录密码不能为空',201,()=>{})
            return false;
        }
        if(this.data.password != this.data.re_password){
            config.toast('两次密码输入不一致，请重新输入',201,()=>{})
            return false;
        }
        wx.showModal({
            title:"提示",
            content:"是否确认修改密码？修改后请牢记您的账号密码，不要告诉别人哦。",
            success:a=>{
                if(a.confirm){
                    request({
                        url:"/miniprogram/user/changePassword",
                        data:{user_id:this.data.user_id,username:this.data.username,password:this.data.password,re_password:this.data.re_password},
                        type:'post',
                    }).then(res=>{
                        config.toast(res.msg,res.code,()=>{})
                        if(res.code == 200){
                            wx.navigateBack()
                        }
                    })
                }
            }
        })
    }
});